layui.use(['form', 'element', 'utils', 'upload', 'slidePanel'], function () {
    var form = layui.form,
        element = layui.element,
        layer = layui.layer,
        $ = layui.$,
        utils = layui.utils,
        upload = layui.upload,
        slidePanel = layui.slidePanel;

    var parentIndex = layer.index;

    /**
     *  定义模板
     */
    var panelTempl = $('#tplPanel').html(); // 添加容器

    var eduTempl = $('#tplEdu').html(); // 教育经历
    var workTempl = $('#tplWork').html(); // 工作经历
    var projectTempl = $('#tplProject').html(); // 工作经历
    var skillTempl = $('#tplSkill').html(); // 技能信息
    var credentialsTempl = $('#tplCredentials').html(); // 证书信息
    var patentsTempl = $('#tplPatents').html(); // 发明专利
    var publicationsTempl = $('#tplPublications').html(); // 作品信息
    var remarksTempl = $('#tplRemarks').html(); // 人才备注信息
    var taginfosTempl = $('#tplTaginfos').html(); // 人才备注信息
    var honorTempl = $('#tplHonor').html(); //荣誉奖项

    /**
     *  定义组件
     */
    // panel
    Vue.component('panel', {
        template: panelTempl,
        props: {
            title: {
                type: String,
                default: '' // 默认值
            },
        },
        methods: {
            handleAddBtnClick: function() {
                this.$emit('add'); // 触发父组件定义的事件
            }
        }
    });

    // 教育经历
    Vue.component('edu', {
        template: eduTempl,
        props: {
            data: {
                type: Object,
                default: function() {
                    return {}
                }
            },
            deleteable: {
                type: Boolean,
                default: true
            }
        },
        data: function() {
            return {
                form: {
                    id: '',
                    eduBeginDate: '',
                    eduEndDate: '',
                    education: '',
                    schoolName: '',
                    collegeName: '',
                    major: '',
                    isTongzhao: '',
                    onEdu: '',
                    remark: '',
                    isNew: false,
                }
            }
        },
        mounted: function () {
            this.getData();
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value) {
                        utils.copyObject(this.form, value)
                    }
                },
                immediate: true
            }
        },
        methods: {
            getData: function() {
                var obj = {};
                var newIgnoreKey = ['id', 'isNew'];
                var ignoreKey = ['isNew'];
                if (this.form.isNew) {
                    utils.copyObjectWithIgnoreKey(obj, this.form, newIgnoreKey)
                } else {
                    utils.copyObjectWithIgnoreKey(obj, this.form, ignoreKey)
                }
                return obj;
            },
            handleDelete: function() {
                this.$emit('delete', this.form.id)
            }
        }
    });
    Vue.component('eduModular', {
        template: '<panel :title="title" @add="handleAdd">' +
            '   <edu ref="edu" v-for="item in lists" :key="item.id" :data="item" :deleteable="lists.length > 1" @delete="handleDelete"></edu>' +
            '</panel>',
        props: {
            data: {
                type: Array,
                default: function () {
                    return []
                }
            },
            title: {
                type: String,
                default: ''
            }
        }, // 向下传递数据给子组件
        data: function() {
            return {
                lists: []
            }
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value && value.length) {
                        this.lists = value
                    } else {
                        this.lists = [
                            this.createNewItem() //创建新的item
                        ]
                    }
                },
                immediate: true //立即调用
            }
        },
        methods: {
            createNewItem: function () {
                return {
                    id: utils.generateUUID(),
                    eduBeginDate: '',
                    eduEndDate: '',
                    education: '',
                    schoolName: '',
                    collegeName: '',
                    major: '',
                    isTongzhao: '',
                    onEdu: '',
                    remark: '',
                    isNew: true
                }
            },
            getData: function() {
                var $item = this.$refs.edu;
                var data = [];

                $item.forEach(function(item) {
                    data.push(item.getData())
                });
                return data;
            }, // 获取数据
            handleAdd: function() {
                var item = this.createNewItem();
                this.lists.push(item);
                this.$nextTick(function () {
                    form.render();
                })
            },
            handleDelete: function(id) {
                for (var index = 0; index < this.lists.length; index++) {
                    if (this.lists[index].id === id) {
                        this.lists.splice(index, 1);
                        return
                    }
                }
            }
        }
    });

    // 工作经历
    Vue.component('work', {
        template: workTempl,
        props: {
            data: {
                type: Object,
                default: function() {
                    return {}
                }
            },
            deleteable: {
                type: Boolean,
                default: true
            }
        },
        data: function() {
            return {
                form: {
                    id: '',
                    workBeginDate: '',
                    workEndDate: '',
                    onWork: '',
                    workCompany: '',
                    functions: '',
                    positions: '',
                    department: '',
                    salary: '',
                    substaffNumber: '',
                    jobLocation: '',
                    reasonsForLeaving: '',
                    remark: '',
                    isNew: false,
                }
            }
        },
        mounted: function () {
            this.getData();
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value) {
                        utils.copyObject(this.form, value)
                    }
                },
                immediate: true
            }
        },
        methods: {
            getData: function() {
                var obj = {};
                var newIgnoreKey = ['id', 'isNew'];
                var ignoreKey = ['isNew'];
                if (this.form.isNew) {
                    utils.copyObjectWithIgnoreKey(obj, this.form, newIgnoreKey)
                } else {
                    utils.copyObjectWithIgnoreKey(obj, this.form, ignoreKey)
                }
                return obj;
            },
            handleDelete: function() {
                this.$emit('delete', this.form.id)
            }
        }
    });
    Vue.component('workModular', {
        template: '<panel :title="title" @add="handleAdd">' +
            '   <work ref="work" v-for="item in lists" :key="item.id" :data="item" :deleteable="lists.length > 1" @delete="handleDelete"></work>' +
            '</panel>',
        props: {
            data: {
                type: Array,
                default: function () {
                    return []
                }
            },
            title: {
                type: String,
                default: ''
            }
        }, // 向下传递数据给子组件
        data: function() {
            return {
                lists: []
            }
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value && value.length) {
                        this.lists = value
                    } else {
                        this.lists = [
                            this.createNewItem() //创建新的item
                        ]
                    }
                },
                immediate: true //立即调用
            }
        },
        methods: {
            createNewItem: function () {
                return {
                    id: utils.generateUUID(),
                    workBeginDate: '',
                    workEndDate: '',
                    onWork: '',
                    workCompany: '',
                    functions: '',
                    positions: '',
                    department: '',
                    salary: '',
                    substaffNumber: '',
                    jobLocation: '',
                    reasonsForLeaving: '',
                    remark: '',
                    isNew: true
                }
            },
            getData: function() {
                var $item = this.$refs.work;
                var data = [];

                $item.forEach(function(item) {
                    data.push(item.getData())
                });
                return data;
            }, // 获取数据
            handleAdd: function() {
                var item = this.createNewItem();
                this.lists.push(item);
                this.$nextTick(function () {
                    form.render();
                })
            },
            handleDelete: function(id) {
                for (var index = 0; index < this.lists.length; index++) {
                    if (this.lists[index].id === id) {
                        this.lists.splice(index, 1);
                        return
                    }
                }
            }
        }
    });

    // 项目经历
    Vue.component('project', {
        template: projectTempl,
        props: {
            data: {
                type: Object,
                default: function() {
                    return {}
                }
            },
            deleteable: {
                type: Boolean,
                default: true
            }
        },
        data: function() {
            return {
                form: {
                    id: '',
                    projectBeginDate: '',
                    projectEndDate: '',
                    positions: '',
                    projectName: '',
                    remark: '',
                    isNew: false,
                }
            }
        },
        mounted: function () {
            this.getData();
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value) {
                        utils.copyObject(this.form, value)
                    }
                },
                immediate: true
            }
        },
        methods: {
            getData: function() {
                var obj = {};
                var newIgnoreKey = ['id', 'isNew'];
                var ignoreKey = ['isNew'];
                if (this.form.isNew) {
                    utils.copyObjectWithIgnoreKey(obj, this.form, newIgnoreKey)
                } else {
                    utils.copyObjectWithIgnoreKey(obj, this.form, ignoreKey)
                }
                return obj;
            },
            handleDelete: function() {
                this.$emit('delete', this.form.id)
            }
        }
    });
    Vue.component('projectModular', {
        template: '<panel :title="title" @add="handleAdd">' +
            '   <project ref="project" v-for="item in lists" :key="item.id" :data="item" :deleteable="lists.length > 1" @delete="handleDelete"></project>' +
            '</panel>',
        props: {
            data: {
                type: Array,
                default: function () {
                    return []
                }
            },
            title: {
                type: String,
                default: ''
            }
        }, // 向下传递数据给子组件
        data: function() {
            return {
                lists: []
            }
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value && value.length) {
                        this.lists = value
                    } else {
                        this.lists = [
                            this.createNewItem() //创建新的item
                        ]
                    }
                },
                immediate: true //立即调用
            }
        },
        methods: {
            createNewItem: function () {
                return {
                    id: utils.generateUUID(),
                    projectBeginDate: '',
                    projectEndDate: '',
                    positions: '',
                    projectName: '',
                    remark: '',
                    isNew: true
                }
            },
            getData: function() {
                var $item = this.$refs.project;
                var data = [];

                $item.forEach(function(item) {
                    data.push(item.getData())
                });
                return data;
            }, // 获取数据
            handleAdd: function() {
                var item = this.createNewItem();
                this.lists.push(item);
                this.$nextTick(function () {
                    form.render();
                })
            },
            handleDelete: function(id) {
                for (var index = 0; index < this.lists.length; index++) {
                    if (this.lists[index].id === id) {
                        this.lists.splice(index, 1);
                        return
                    }
                }
            }
        }
    });

    // 技能信息
    Vue.component('skill', {
        template: skillTempl,
        props: {
            data: {
                type: Object,
                default: function() {
                    return {}
                }
            },
            deleteable: {
                type: Boolean,
                default: true
            }
        },
        data: function() {
            return {
                form: {
                    id: '',
                    languageName: '',
                    languageFraction: '',
                    languageLevel: '',
                    remark: '',
                    isNew: false,
                }
            }
        },
        mounted: function () {
            this.getData();
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value) {
                        utils.copyObject(this.form, value)
                    }
                },
                immediate: true
            }
        },
        methods: {
            getData: function() {
                var obj = {};
                var newIgnoreKey = ['id', 'isNew'];
                var ignoreKey = ['isNew'];
                if (this.form.isNew) {
                    utils.copyObjectWithIgnoreKey(obj, this.form, newIgnoreKey)
                } else {
                    utils.copyObjectWithIgnoreKey(obj, this.form, ignoreKey)
                }
                return obj;
            },
            handleDelete: function() {
                this.$emit('delete', this.form.id)
            }
        }
    });
    Vue.component('skillModular', {
        template: '<panel :title="title" @add="handleAdd">' +
            '   <skill ref="skill" v-for="item in lists" :key="item.id" :data="item" :deleteable="lists.length > 1" @delete="handleDelete"></skill>' +
            '</panel>',
        props: {
            data: {
                type: Array,
                default: function () {
                    return []
                }
            },
            title: {
                type: String,
                default: ''
            }
        }, // 向下传递数据给子组件
        data: function() {
            return {
                lists: []
            }
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value && value.length) {
                        this.lists = value
                    } else {
                        this.lists = [
                            this.createNewItem() //创建新的item
                        ]
                    }
                },
                immediate: true //立即调用
            }
        },
        methods: {
            createNewItem: function () {
                return {
                    id: utils.generateUUID(),
                    languageName: '',
                    languageFraction: '',
                    languageLevel: '',
                    remark: '',
                    isNew: true
                }
            },
            getData: function() {
                var $item = this.$refs.skill;
                var data = [];

                $item.forEach(function(item) {
                    data.push(item.getData())
                });
                return data;
            }, // 获取数据
            handleAdd: function() {
                var item = this.createNewItem();
                this.lists.push(item);
                this.$nextTick(function () {
                    form.render();
                })
            },
            handleDelete: function(id) {
                for (var index = 0; index < this.lists.length; index++) {
                    if (this.lists[index].id === id) {
                        this.lists.splice(index, 1);
                        return
                    }
                }
            }
        }
    });

    // 证书信息
    Vue.component('credentials', {
        template: credentialsTempl,
        props: {
            data: {
                type: Object,
                default: function() {
                    return {}
                }
            },
            deleteable: {
                type: Boolean,
                default: true
            }
        },
        data: function() {
            return {
                form: {
                    id: '',
                    credentialName: '',
                    credentialType: '',
                    credentialTime: '',
                    isNew: false,
                }
            }
        },
        mounted: function () {
            this.getData();
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value) {
                        utils.copyObject(this.form, value)
                    }
                },
                immediate: true
            }
        },
        methods: {
            getData: function() {
                var obj = {};
                var newIgnoreKey = ['id', 'isNew'];
                var ignoreKey = ['isNew'];
                if (this.form.isNew) {
                    utils.copyObjectWithIgnoreKey(obj, this.form, newIgnoreKey)
                } else {
                    utils.copyObjectWithIgnoreKey(obj, this.form, ignoreKey)
                }
                return obj;
            },
            handleDelete: function() {
                this.$emit('delete', this.form.id)
            }
        }
    });
    Vue.component('credentialsModular', {
        template: '<panel :title="title" @add="handleAdd">' +
            '   <credentials ref="credentials" v-for="item in lists" :key="item.id" :data="item" :deleteable="lists.length > 1" @delete="handleDelete"></credentials>' +
            '</panel>',
        props: {
            data: {
                type: Array,
                default: function () {
                    return []
                }
            },
            title: {
                type: String,
                default: ''
            }
        }, // 向下传递数据给子组件
        data: function() {
            return {
                lists: []
            }
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value && value.length) {
                        this.lists = value
                    } else {
                        this.lists = [
                            this.createNewItem() //创建新的item
                        ]
                    }
                },
                immediate: true //立即调用
            }
        },
        methods: {
            createNewItem: function () {
                return {
                    id: utils.generateUUID(),
                    credentialName: '',
                    credentialType: '',
                    credentialTime: '',
                    isNew: true
                }
            },
            getData: function() {
                var $item = this.$refs.credentials;
                var data = [];

                $item.forEach(function(item) {
                    data.push(item.getData())
                });
                return data;
            }, // 获取数据
            handleAdd: function() {
                var item = this.createNewItem();
                this.lists.push(item);
                this.$nextTick(function () {
                    form.render();
                })
            },
            handleDelete: function(id) {
                for (var index = 0; index < this.lists.length; index++) {
                    if (this.lists[index].id === id) {
                        this.lists.splice(index, 1);
                        return
                    }
                }
            }
        }
    });

    // 发明专利
    Vue.component('patents', {
        template: patentsTempl,
        props: {
            data: {
                type: Object,
                default: function() {
                    return {}
                }
            },
            deleteable: {
                type: Boolean,
                default: true
            }
        },
        data: function() {
            return {
                form: {
                    id: '',
                    patentName: '',
                    patentTime: '',
                    isNew: false,
                }
            }
        },
        mounted: function () {
            this.getData();
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value) {
                        utils.copyObject(this.form, value)
                    }
                },
                immediate: true
            }
        },
        methods: {
            getData: function() {
                var obj = {};
                var newIgnoreKey = ['id', 'isNew'];
                var ignoreKey = ['isNew'];
                if (this.form.isNew) {
                    utils.copyObjectWithIgnoreKey(obj, this.form, newIgnoreKey)
                } else {
                    utils.copyObjectWithIgnoreKey(obj, this.form, ignoreKey)
                }
                return obj;
            },
            handleDelete: function() {
                this.$emit('delete', this.form.id)
            }
        }
    });
    Vue.component('patentsModular', {
        template: '<panel :title="title" @add="handleAdd">' +
            '   <patents ref="patents" v-for="item in lists" :key="item.id" :data="item" :deleteable="lists.length > 1" @delete="handleDelete"></patents>' +
            '</panel>',
        props: {
            data: {
                type: Array,
                default: function () {
                    return []
                }
            },
            title: {
                type: String,
                default: ''
            }
        }, // 向下传递数据给子组件
        data: function() {
            return {
                lists: []
            }
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value && value.length) {
                        this.lists = value
                    } else {
                        this.lists = [
                            this.createNewItem() //创建新的item
                        ]
                    }
                },
                immediate: true //立即调用
            }
        },
        methods: {
            createNewItem: function () {
                return {
                    id: utils.generateUUID(),
                    patentName: '',
                    patentTime: '',
                    isNew: true
                }
            },
            getData: function() {
                var $item = this.$refs.patents;
                var data = [];

                $item.forEach(function(item) {
                    data.push(item.getData())
                });
                return data;
            }, // 获取数据
            handleAdd: function() {
                var item = this.createNewItem();
                this.lists.push(item);
                this.$nextTick(function () {
                    form.render();
                })
            },
            handleDelete: function(id) {
                for (var index = 0; index < this.lists.length; index++) {
                    if (this.lists[index].id === id) {
                        this.lists.splice(index, 1);
                        return
                    }
                }
            }
        }
    });

    // 作品信息
    Vue.component('publications', {
        template: publicationsTempl,
        props: {
            data: {
                type: Object,
                default: function() {
                    return {}
                }
            },
            deleteable: {
                type: Boolean,
                default: true
            }
        },
        data: function() {
            return {
                form: {
                    id: '',
                    publicationName: '',
                    authors: '',
                    publicationOrg: '',
                    publicationTime: '',
                    description: '',
                    isNew: false,
                }
            }
        },
        mounted: function () {
            this.getData();
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value) {
                        utils.copyObject(this.form, value)
                    }
                },
                immediate: true
            }
        },
        methods: {
            getData: function() {
                var obj = {};
                var newIgnoreKey = ['id', 'isNew'];
                var ignoreKey = ['isNew'];
                if (this.form.isNew) {
                    utils.copyObjectWithIgnoreKey(obj, this.form, newIgnoreKey)
                } else {
                    utils.copyObjectWithIgnoreKey(obj, this.form, ignoreKey)
                }
                return obj;
            },
            handleDelete: function() {
                this.$emit('delete', this.form.id)
            }
        }
    });
    Vue.component('publicationsModular', {
        template: '<panel :title="title" @add="handleAdd">' +
            '   <publications ref="publications" v-for="item in lists" :key="item.id" :data="item" :deleteable="lists.length > 1" @delete="handleDelete"></publications>' +
            '</panel>',
        props: {
            data: {
                type: Array,
                default: function () {
                    return []
                }
            },
            title: {
                type: String,
                default: ''
            }
        }, // 向下传递数据给子组件
        data: function() {
            return {
                lists: []
            }
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value && value.length) {
                        this.lists = value
                    } else {
                        this.lists = [
                            this.createNewItem() //创建新的item
                        ]
                    }
                },
                immediate: true //立即调用
            }
        },
        methods: {
            createNewItem: function () {
                return {
                    id: utils.generateUUID(),
                    publicationName: '',
                    authors: '',
                    publicationOrg: '',
                    publicationTime: '',
                    description: '',
                    isNew: true
                }
            },
            getData: function() {
                var $item = this.$refs.publications;
                var data = [];

                $item.forEach(function(item) {
                    data.push(item.getData())
                });
                return data;
            }, // 获取数据
            handleAdd: function() {
                var item = this.createNewItem();
                this.lists.push(item);
                this.$nextTick(function () {
                    form.render();
                })
            },
            handleDelete: function(id) {
                for (var index = 0; index < this.lists.length; index++) {
                    if (this.lists[index].id === id) {
                        this.lists.splice(index, 1);
                        return
                    }
                }
            }
        }
    });

    // 人才备注信息
    Vue.component('remarks', {
        template: remarksTempl,
        props: {
            data: {
                type: Object,
                default: function() {
                    return {}
                }
            },
            deleteable: {
                type: Boolean,
                default: true
            }
        },
        data: function() {
            return {
                form: {
                    id: '',
                    jobBranchInterviewId: '',
                    biType: '',
                    biDate: '',
                    communication: '',
                    thinkLogic: '',
                    matchedDegree: '',
                    jobHunting: '',
                    softerSkills: '',
                    appearanceBearing: '',
                    biPlace: '',
                    biRemark: '',
                    isNew: false,
                }
            }
        },
        mounted: function () {
            this.getData();
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value) {
                        utils.copyObject(this.form, value)
                    }
                },
                immediate: true
            }
        },
        methods: {
            getData: function() {
                var obj = {};
                var newIgnoreKey = ['id', 'isNew'];
                var ignoreKey = ['isNew'];
                if (this.form.isNew) {
                    utils.copyObjectWithIgnoreKey(obj, this.form, newIgnoreKey)
                } else {
                    utils.copyObjectWithIgnoreKey(obj, this.form, ignoreKey)
                }
                return obj;
            },
            handleDelete: function() {
                this.$emit('delete', this.form.id)
            }
        }
    });
    Vue.component('remarksModular', {
        template: '<panel :title="title" @add="handleAdd">' +
            '   <remarks ref="remarks" v-for="item in lists" :key="item.id" :data="item" :deleteable="lists.length > 1" @delete="handleDelete"></remarks>' +
            '</panel>',
        props: {
            data: {
                type: Array,
                default: function () {
                    return []
                }
            },
            title: {
                type: String,
                default: ''
            }
        }, // 向下传递数据给子组件
        data: function() {
            return {
                lists: []
            }
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value && value.length) {
                        this.lists = value
                    } else {
                        this.lists = [
                            this.createNewItem() //创建新的item
                        ]
                    }
                },
                immediate: true //立即调用
            }
        },
        methods: {
            createNewItem: function () {
                return {
                    id: utils.generateUUID(),
                    jobBranchInterviewId: '',
                    biType: '',
                    biDate: '',
                    communication: '',
                    thinkLogic: '',
                    matchedDegree: '',
                    jobHunting: '',
                    softerSkills: '',
                    appearanceBearing: '',
                    biPlace: '',
                    biRemark: '',
                    isNew: true
                }
            },
            getData: function() {
                var $item = this.$refs.remarks;
                var data = [];

                $item.forEach(function(item) {
                    data.push(item.getData())
                });
                return data;
            }, // 获取数据
            handleAdd: function() {
                var item = this.createNewItem();
                this.lists.push(item);
                this.$nextTick(function () {
                    form.render();
                })
            },
            handleDelete: function(id) {
                for (var index = 0; index < this.lists.length; index++) {
                    if (this.lists[index].id === id) {
                        this.lists.splice(index, 1);
                        return
                    }
                }
            }
        }
    });

    // 标签信息
    Vue.component('taginfos', {
        template: taginfosTempl,
        props: {
            data: {
                type: Object,
                default: function() {
                    return {}
                }
            },
            deleteable: {
                type: Boolean,
                default: true
            }
        },
        data: function() {
            return {
                form: {
                    id: '',
                    tagName: '',
                    remark: '',
                    isNew: false,
                }
            }
        },
        mounted: function () {
            this.getData();
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value) {
                        utils.copyObject(this.form, value)
                    }
                },
                immediate: true
            }
        },
        methods: {
            getData: function() {
                var obj = {};
                var newIgnoreKey = ['id', 'isNew'];
                var ignoreKey = ['isNew'];
                if (this.form.isNew) {
                    utils.copyObjectWithIgnoreKey(obj, this.form, newIgnoreKey)
                } else {
                    utils.copyObjectWithIgnoreKey(obj, this.form, ignoreKey)
                }
                return obj;
            },
            handleDelete: function() {
                this.$emit('delete', this.form.id)
            }
        }
    });
    Vue.component('taginfosModular', {
        template: '<panel :title="title" @add="handleAdd">' +
            '   <taginfos ref="taginfos" v-for="item in lists" :key="item.id" :data="item" :deleteable="lists.length > 1" @delete="handleDelete"></taginfos>' +
            '</panel>',
        props: {
            data: {
                type: Array,
                default: function () {
                    return []
                }
            },
            title: {
                type: String,
                default: ''
            }
        }, // 向下传递数据给子组件
        data: function() {
            return {
                lists: []
            }
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value && value.length) {
                        this.lists = value
                    } else {
                        this.lists = [
                            this.createNewItem() //创建新的item
                        ]
                    }
                },
                immediate: true //立即调用
            }
        },
        methods: {
            createNewItem: function () {
                return {
                    id: utils.generateUUID(),
                    tagName: '',
                    remark: '',
                    isNew: true
                }
            },
            getData: function() {
                var $item = this.$refs.taginfos;
                var data = [];

                $item.forEach(function(item) {
                    data.push(item.getData())
                });
                return data;
            }, // 获取数据
            handleAdd: function() {
                var item = this.createNewItem();
                this.lists.push(item);
                this.$nextTick(function () {
                    form.render();
                })
            },
            handleDelete: function(id) {
                for (var index = 0; index < this.lists.length; index++) {
                    if (this.lists[index].id === id) {
                        this.lists.splice(index, 1);
                        return
                    }
                }
            }
        }
    });

    // 荣誉奖项
    Vue.component('honor', {
        template: honorTempl,
        props: {
            data: {
                type: Object,
                default: function() {
                    return {}
                }
            },
            deleteable: {
                type: Boolean,
                default: true
            }
        },
        data: function() {
            return {
                form: {
                    id: '',
                    honorName: '',
                    honorOrg: '',
                    honorTime: '',
                    isNew: false
                }
            }
        },
        mounted: function () {
            this.getData();
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value) {
                        utils.copyObject(this.form, value)
                    }
                },
                immediate: true
            }
        },
        methods: {
            getData: function() {
                var obj = {};
                var newIgnoreKey = ['id', 'isNew'];
                var ignoreKey = ['isNew'];
                if (this.form.isNew) {
                    utils.copyObjectWithIgnoreKey(obj, this.form, newIgnoreKey)
                } else {
                    utils.copyObjectWithIgnoreKey(obj, this.form, ignoreKey)
                }
                return obj;
            },
            handleDelete: function() {
                this.$emit('delete', this.form.id)
            }
        }
    });
    Vue.component('honorModular', {
        template: '<panel :title="title" @add="handleAdd">' +
            '   <honor ref="honor" v-for="item in lists" :key="item.id" :data="item" :deleteable="lists.length > 1" @delete="handleDelete"></honor>' +
            '</panel>',
        props: {
            data: {
                type: Array,
                default: function () {
                    return []
                }
            },
            title: {
                type: String,
                default: ''
            }
        }, // 向下传递数据给子组件
        data: function() {
            return {
                lists: []
            }
        },
        watch: {
            data: {
                handler: function(value) {
                    if (value && value.length) {
                        this.lists = value
                    } else {
                        this.lists = [
                            this.createNewItem() //创建新的item
                        ]
                    }
                },
                immediate: true //立即调用
            }
        },
        methods: {
            createNewItem: function () {
                return {
                    id: utils.generateUUID(),
                    honorName: '',
                    honorOrg: '',
                    honorTime: '',
                    isNew: true
                }
            },
            getData: function() {
                var $item = this.$refs.honor;
                var data = [];

                $item.forEach(function(item) {
                    data.push(item.getData())
                });
                return data;
            }, // 获取数据
            handleAdd: function() {
                var item = this.createNewItem();
                this.lists.push(item);
                this.$nextTick(function () {
                    form.render();
                })
            },
            handleDelete: function(id) {
                for (var index = 0; index < this.lists.length; index++) {
                    if (this.lists[index].id === id) {
                        this.lists.splice(index, 1);
                        return
                    }
                }
            }
        }
    });

    window.talentDialogContent = new Vue({
        el: '#talentDialogContent',
        data: function () {
            return {
                fileList: [], // 文件列表
                form: {
                    namecn: "",
                    sex: "",
                    nameen: "",
                    birthsday: "",
                    citys: "",
                    expectedSalary: "",
                    functions: "",
                    industrys: "",
                    intentionalCitys: "",
                    linkedin: "",
                    privateEmail: "",
                    privatePhone: "",
                    topEduDegree: "",
                    isTongzhao: "",
                    position: "",
                    overseasEducation: "",
                    channel: "",
                    overseasExperience: "",
                    qqCode: "",
                    talentStatus: "",
                    weChatCode: "",
                    workEmail: "",
                    workPhone: "",
                    yearSalary: "",
                    personalId: "",
                    graduationYear: "",
                    lastMajor: "",
                    ethnicity: "",
                    nationality: "",
                    hukou: "",
                    birthplace: "",
                    englishLevel: "",
                    lastSchool: "",
                    expectedOnboardTime: "",
                    yearOfWorkExperience: "",
                    startYearOfEmployment: "",
                    currentStatus: "",
                    maritalStatus: "",
                    politicsStatus: "",
                    address: "",
                    hobbies: "",
                    remark: "",
                }, // 基础信息
                educationexps: [], // 教育经历
                workexps: [], // 工作经历
                projectexps: [], // 项目经历
                languageskills: [], // 技能信息
                credentials: [], // 证书信息
                patents: [], // 发明专利
                publications: [], // 作品信息
                remarks: [], // 人才备注信息
                taginfos: [], // 标签信息
                honors: [] // 荣誉奖项
            }
        },
        mounted: function () {
            form.render();
            if (window.userId) {
                this.getTalentInfo();
                this.getFileList();
            }
        },
        methods: {
            getTalentInfo: function () {
                var that = this;
                utils.Ajax({
                    url: 'api/talent.json',
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'get',
                    data: {id: window.userId},
                    success: function (response) {
                        var data = response.data;

                        utils.copySelfObject(that.form, data); //基础表单

                        that.educationexps = data.educationexps; //教育经历
                        that.workexps = data.workexps; //工作经历
                        that.projectexps = data.projectexps; //项目经历
                        that.languageskills = data.languageskills, // 技能信息
                        that.credentials = data.credentials, // 证书信息
                        that.patents = data.patents, // 发明专利
                        that.publications = data.publications, // 作品信息
                        that.remarks = data.remarks, // 人才备注信息
                        that.taginfos = data.taginfos, // 标签信息
                        that.honors = data.honors; //荣誉奖项

                        // 重新渲染表单
                        that.$nextTick(function () {
                            form.render();
                        })

                    }
                })
            },
            getFileList: function () {
                var that = this;
                utils.Ajax({
                    url: 'api/talent_file_list.json',
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    data: {id: window.userId},
                    success: function (response) {
                        var data = response.data;
                        that.fileList = data.fileList;
                    }
                })
            },
            setTalentInfo: function (data) {
                var that = this;
                var resume = data.resume;

                utils.copySelfObject(that.form, resume); //基础表单
                that.educationexps = resume.educationexps; //教育经历
                that.workexps = resume.workexps; //工作经历
                that.projectexps = resume.projectexps; //项目经历
                that.languageskills = resume.languageskills, // 技能信息
                that.credentials = resume.credentials, // 证书信息
                that.patents = resume.patents, // 发明专利
                that.publications = resume.publications, // 作品信息
                that.remarks = resume.remarks, // 人才备注信息
                that.taginfos = resume.taginfos, // 标签信息
                that.honors = resume.honors; //荣誉奖项

                that.fileList.push(data.file); //附件列表

                // 重新渲染表单
                that.$nextTick(function () {
                    form.render();
                })
            },
            getFileData: function () {
                var arr = [];
                $.each(this.fileList, function (index, item) {
                    arr.push(item.id)
                });
                return arr;
            },
            handleDeleteFile: function(id) {
                for (var index = 0; index < this.fileList.length; index++) {
                    if (this.fileList[index].id === id) {
                        this.fileList.splice(index, 1);
                        return
                    }
                }
            },
            handleShowFile: function(data) {
                // 右侧浮窗
                slidePanel.showPanel({
                    content: '<iframe src="'+ data.url +'"></iframe>'
                })
            },
            handleSubmitBtnClick: function() {
                var that = this;
                var obj = {};

                utils.copyObject(obj, that.form); // 基础表单

                if (that.$refs.eduModular) {
                    obj.educationexps = that.$refs.eduModular.getData()
                }
                if (that.$refs.workModular) {
                    obj.workexps = that.$refs.workModular.getData()
                }
                if (that.$refs.projectModular) {
                    obj.projectexps = that.$refs.projectModular.getData()
                }
                if (that.$refs.skillModular) {
                    obj.languageskills = that.$refs.skillModular.getData()
                }
                if (that.$refs.credentialsModular) {
                    obj.credentials = that.$refs.credentialsModular.getData()
                }
                if (that.$refs.patentsModular) {
                    obj.patents = that.$refs.patentsModular.getData()
                }
                if (that.$refs.publicationsModular) {
                    obj.publications = that.$refs.publicationsModular.getData()
                }
                if (that.$refs.remarksModular) {
                    obj.remarks = that.$refs.remarksModular.getData()
                }
                if (that.$refs.taginfosModular) {
                    obj.taginfos = that.$refs.taginfosModular.getData()
                }
                if (that.$refs.honorModular) {
                    obj.honors = that.$refs.honorModular.getData()
                }

                if (that.fileList) {
                    obj.fileList = that.getFileData();
                }

                // 提交
                utils.Ajax({
                    url: '',
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    data: {id: window.userId ,data: JSON.stringify(obj)},
                    success: function (response) {
                        layer.msg(response.message, function () {
                            layer.close(parentIndex);
                        });
                    }
                })
            } //提交
        }
    });

    // 简历照片上传
    $('.handleUploadFile').each(function () {
        var $this = $(this);
        var _tag = $this.data('tag');
        var _type = $this.data('type');
        upload.render({
            elem: $this,
            url: 'api/upload_file.json', //上传接口
            data: {
                tag: _tag,
                type: _type
            },
            accept: 'file',
            before: function(obj){
                var _temp = '<div class="layui-progress layui-progress-big mt-10" lay-filter="progress">' +
                    '<div class="layui-progress-bar layui-bg-lightblue"></div>' +
                    '</div>';
                $this.after(_temp);
            },
            progress: function(n, elem){
                var percent = n + '%';
                element.progress('progress', percent);
            },
            done: function(res){
                if (res.code === 200) {
                    // 移除进度条
                    $this.next('.layui-progress').remove();
                    // 填充数据
                    talentDialogContent.setTalentInfo(res.data);
                    // 右侧浮窗
                    slidePanel.showPanel({
                        content: '<iframe src="'+ res.data.file.url +'"></iframe>'
                    })
                }
            },
            error: function(){
                layer.msg('请求错误！');
            }
        });
    })



});
